package com.xiaoowuu.wherecanigo

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.view.View

/**
 * @author xiaoowuu
 */
class PointView @JvmOverloads constructor(context: Context, private val size: Int, private val color: Int, private val strokeWidth: Int = 0, private val strokeColor: Int = 0) : View(context) {
    private val paint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
    private val defaultPadding = 2

    init {
        paint.color = color
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        val size = this.size + defaultPadding * 2
        setMeasuredDimension(size, size)
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        val centerX = width / 2f
        val centerY = height / 2f
        val radius = size / 2f
        if (strokeWidth > 0) {
            paint.color = strokeColor
            canvas.drawCircle(centerX, centerY, radius, paint)
        }
        paint.color = color
        canvas.drawCircle(centerX, centerY, radius - strokeWidth, paint)
    }
}
